import { BaseCommand, ICmdDialogParams } from '@amcax/base';
import i18n from 'i18next';
import { useEffect, useRef } from 'react';
import CmdInteractor from './CmdInteractor';

function DimintegrationCommand({ onClose }: ICmdDialogParams) {
  const cmdRef = useRef<CmdInteractor>(null);
  useEffect(() => {
    cmdRef.current = new CmdInteractor();
    cmdRef.current.addExit(onClose);
    return () => {
      cmdRef.current?.destroy();
      cmdRef.current = null;
    };
  }, []);
  return <></>;
}

export const Dimintegration: BaseCommand = {
  id: 'integrationDim',
  label: 'command.integration-dim',
  icon: 'commands/sketch/integration-dim',
  group: 'sketch',
  create: (label: string, onClose: () => void) => (
    <DimintegrationCommand
      title={i18n.t(label)}
      onClose={onClose}
    />
  ),
};
